﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace testy {
	public class Question {
		private string content;
		private bool everyProper;
		private byte checkedCount;
		private List<Answer> answers;
		public Question () {
			this.content = "";
			this.everyProper = false;
			this.checkedCount = 0;
			this.answers = new List<Answer>();
		}
		public Question (string content, List<Answer> answers, bool everyProper = false, byte checkedCount = 0) {
			this.content = content;
			this.answers = answers;
			this.everyProper = everyProper;
			this.checkedCount = checkedCount;
		}
		public Question (XmlNode q) : this() {
			XmlElement qs = (XmlElement) q;
			bool.TryParse(qs.GetAttribute("everyProper"), out this.everyProper);
			byte.TryParse(qs.GetAttribute("checkedCount"), out this.checkedCount);
			this.content = qs.GetElementsByTagName("content")[0].InnerText;
			XmlNodeList aas = qs.GetElementsByTagName("answer");
			foreach (XmlNode i in aas) {
				this.answers.Add(new Answer(i));
			}
		}
		public string generateXML () {
			string output = "";
			output += "<question everyProper=\""+this.everyProper+"\" checkedCount=\""+this.checkedCount+"\">";
			output += "<content>" + this.content + "</content>";
			foreach (Answer a in this.answers) {
				output += a.generateXML();
			}
			output += "</question>";
			return output;
		}
		public string Content {
			get { return this.content; }
			set { this.content = value; }
		}
		public bool EveryProper {
			get { return this.everyProper; }
			set { this.everyProper = value; }
		}
		public byte CheckedCount {
			get { return this.checkedCount; }
			set { this.checkedCount = value; }
		}
		public List<Answer> Answers {
			get { return this.answers; }
			set { this.answers = value; }
		}
	}
}
